/*
 *   Copyright (C) 2010  Jens Kieselbach
 * 
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 * 
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 * 
 *   You may obtain a copy of the License at http://www.gnu.org/licenses/gpl.html
 */

package de.kieselbach.grootional.util

import java.awt.image.*
import javax.swing.*

import java.awt.Color
import java.awt.Font
import java.awt.Image
import java.awt.RenderingHints

class TypeIcon extends ImageIcon {

    final static def textColor = new Color (100, 144, 38)
    final static def textFont = new Font(Font.SANS_SERIF, Font.PLAIN, 9)

    TypeIcon(Image img, String txt) {

        BufferedImage bi = new BufferedImage(img.width, img.height, BufferedImage.TYPE_INT_ARGB)

        def g = bi.graphics
        g.drawImage(img, 0, 0, null)

        if(txt != null) {
            g.color = textColor
            g.font = textFont
            g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON)

            g.drawString(txt, 17, 12)
        }

        setImage(bi)
    }
}

